def getIntersectionNode(headA, headB):
    n1, n2 = headA, headB
    while n1 != n2:
        n1 = n1.next if n1 else headB
        n2 = n2.next if n2 else headA

    return n1
